package com.haodai.agency.net;

import android.content.Context;

import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by fanday on 2017/2/23.
 */
public class NetUtils extends RetrofitUtils{

    /**
     * 创建回调对象
     * @param service
     * @param <T>
     * @return
     */
    public static <T> T create(final Class<T> service) {
        return getRetrofit().create(service);
    }
    /**
     * 插入观察者
     * @param observable
     * @param observer
     * @param <T>
     */
    public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) {
        observable.subscribeOn(Schedulers.io())
                .subscribeOn(Schedulers.newThread())//子线程访问网络
                .observeOn(AndroidSchedulers.mainThread())//回调到主线程
                .subscribe(observer);
    }
}
